package com.xdj.service.impl;

import com.xdj.mapper.CategoryMapper;
import com.xdj.mapper.UserMapper;
import com.xdj.pojo.Category;
import com.xdj.service.CategoryService;
import com.xdj.utils.JwtUtil;
import com.xdj.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.catalog.Catalog;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * ClassName: CategoryDerviceImpl
 * Package: com.xdj.service.impl
 * Description:
 *
 * @Author: 信
 * @Create: 2024/1/11 - 21:09
 */
@Service
public class CategoryDerviceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(Category category) {
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());

        Map<String, Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        category.setCreateUser(userId);

        categoryMapper.insert(category);
    }

    //正确  看sql语句返回内容
    @Override
    public List<Category> list() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");

        return categoryMapper.list(id);
    }

    @Override
    public Category detail(Integer id) {
        Category category = categoryMapper.findById(id);
        return category;
    }

    @Override
    public void update(Category category) {
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }


}
